function checkUsername(userval)
{
  if(userval != "")
  {  	
    $.post('include/userHanlder.inc.php',{ varUsername : userval }, function(userval)
    {
      var first = get_message("invalidusername");
      var second = get_message("invalidusername2");
      
      var error = '<div id="invalidusername" class="error">'
                   + '<p>'
                   + '<strong>'+ first +'</strong>' + second
                   + '</p>'
                   + '</div>';
      
      if(userval=='yes') //se lo username esiste già
      {
          if(($("#invalidusername").length > 0)){
            $('#invalidusername').effect("shake", { times: 4 }, 100);
          }  
          
          if (!($("#invalidusername").length > 0)){
           $('#pick-username').after(error);
           $('#invalidusername').slideDown("slow");
          }

      }
      else
      {
          $('#invalidusername').slideUp("slow");
      }   					
  	});	
	}
  else
  {
     $('#invalidusername').slideUp("slow");
  } 		    
}

function matchPassword(passval)
{
   if((passval != "") && ($('#choose-password').val() != ""))
   {
      if(passval != $('#repeat-password').val())
      {   
          var first = get_message("invalidmatchpassw");
          var second = get_message("invalidmatchpassw2");
          var error = '<div id="invalidretype" class="error">'
                      +'<p>'
                      +'<strong>'+ first +'</strong>'+ second
                      +'</p>'
                      +'</div>';
                      
          if(($("#invalidretype").length > 0)){
              $('#invalidretype').effect("shake", { times: 4 }, 100);
          }
          
          if(!($("#invalidretype").length > 0)){
          $('#repeat-password').after(error);      
          $('#invalidretype').slideDown("slow");
        }
      }
   }
   else
   {
     $('#invalidretype').slideUp("slow");
   }
}


function checkMail(mailval)
{
   if(mailval != "")
   {
      var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;

      if(!(pattern.test(mailval)))
      { 
        var first = get_message("invalidmail");
        var second = get_message("invalidmail2");
        var error = '<div id="invalidemail" class="error">' 
                + '<p>'
                + '<strong>'+ first +'</strong>'
                + second
                + '</p>'
                + '</div>';
                
        if (!($("#invalidemail").length > 0)){
           $('#user-email').after(error);
        }
        $('#invalidemail').slideDown("slow"); 
      }
      else
      {
        $('#invalidemail').slideUp("slow");
      }
   }
   else
   {
        $('#invalidemail').slideUp("slow");
   }
}

/*
function addUserGift()
{		  		  
				var title = $('#titleGift').val();
				var link = encodeURI($('#linkGift').val());
				//var description = encodeURI($('#descriptionGift').val());
				var list = $('#list').val();
				var ajaxattempt = $('#hiddenUserGift').val();	
				
				
				$.ajax({
								
					//url: 'include/backOfficeHandler.inc.php',
					url: 'ManagePage.do?page=add_gift',
					cache: false,
					type: 'get',
					//data: 'title=' + title + '&link=' + link + '&description=' + description +'&list='+ list +'&ajaxattempt=' + ajaxattempt,
					//dataType: 'json',
					data: 'title=' + title + '&link=' + link + '&list='+ list ,
					
					
		      success: function(result) {
		           
		           alert("successo");
		           
                $('#msg_list').append('<div id="zebra" class="zebra "><p class="msg_head"/>'+
		                                  '<h3 id="tit'+result.id+'" class="msg_head">'+result.link_name+'</h3>'+
                                      '<div class="msg_body " style="display: none;">'+
                                      '<fieldset><div class="even"><div id="formmodifyusergift" class=" "></div>'+
                                      '<div id="formdeleteusergift" class="even"> </div><table><tbody><tr><td><label for="title">'+
                                      'Title:</label></td><td><input id="title'+result.id+'" class="textfield" type="text" name="title" maxlength="100"'+
                                      ' value="'+result.link_name+'"/></td></tr><tr><td><label for="link">Link:</label></td>'+
                                      '<td><input id="link'+result.id+'" class="textfield" type="text" name="link" maxlength="255"'+
                                      ' value="'+result.link+'"/></td></tr><tr><td>'+
                                      '<label for="comment">Additional info:</label></td><td>'+
                                      '<input id="description'+result.id+'" class="textfield" type="text"'+
                                      ' value="'+result.description+'" name="description" maxlength="255"/></td></tr><tr><td><input id="hiddenmodUserGift" type="hidden" name="ajaxattempt" value="editusergift"/>'+
                                      '<input id="m'+result.id+'" class="savegiftideas" type="image" alt="save" src="img/btn-save.gif"/></td><td><input id="hiddendelUserGift" type="hidden" name="ajaxattempt" value="deleteusergift"/>'+
                                      '<input id="i'+result.id+'" class="usrdeletebtn" type="image" alt="delete" src="img/btn-delete.gif"/></td></tr></tbody></table></div></fieldset></div></div>'
                                      );
                $(".msg_list div:even").addClass("even");
                $(".msg_list div:odd").addClass("odd");
                $(".msg_head:last").bind('click', function(){$(this).next(".msg_body").slideToggle(600);	});
                $('.usrdeletebtn:last').bind('click', function(){delUserGift($(this).attr("id") );});
                $('.savegiftideas:last').bind('click', function(){modUserGift($(this).attr("id"));});
                 
              }

				});
			  			  
			  $('#titleGift').val("");
        $('#descriptionGift').val("");
        $('#linkGift').val("");
	
				return false;	
				
}
*/
function delUserGift(idn)
{
         var id = idn.substring(1);
		     var ajaxattempt = $('#hiddendelUserGift').val();
		
		
        if(confirm("Are you sure?"))
        {			
        	
    				$.ajax({
    				
    					url: 'include/backOfficeHandler.inc.php',
    					type: 'POST',
    					data: 'id=' + id +'&ajaxattempt=' + ajaxattempt,
    					
    					success: function(result) {
						   $("#i"+id).parents('div#zebra').effect("explode");
						  
					     }
    					
    				});
        }	
        return false;
}
function modUserGift(idval)
{				
        var id = idval.substring(1);
				var title = $("#title"+id).val();
				var link = $("#link"+id).val();
				var description = encodeURI($("#description"+id).val());
				var ajaxattempt = $('#hiddenmodUserGift').val();
							
				$.ajax({
								
					url: 'include/backOfficeHandler.inc.php',
					type: 'POST',
					data: 'title=' + title + '&link=' + link + '&description=' + description +'&id='+ id +'&ajaxattempt=' + ajaxattempt,
				
					success: function(result) {
					
					  $(".msg_body").hide("slow");
	   				$("#m"+id).parents('div#zebra').effect("highlight", {}, 3000);
	   				$("#tit"+id).text(title);
					     }   
				});
				return false;	
}


function addListGift()
{	
				var name = $('#namelist').val();
				var ajaxattempt = $('#hiddenAddList').val();
				
				$.ajax({
								
					url: 'include/backOfficeHandler.inc.php',
					type: 'POST',
					data: 'name=' + name +'&ajaxattempt=' + ajaxattempt,
					
					success: function(result) {
						
				$('.listname').text(name);
						$('.managetitle').hide("slow");
						$('.listname').effect("highlight", {}, 3000);
					

					}
				});
				
				return false;	
				
}
function editListGift()
{		  		  
				var name = $('#namelist').val();
				var idlist = $('#list').val();
				var ajaxattempt = $('#hiddenModList').val();
				
				$.ajax({
								
					url: 'include/backOfficeHandler.inc.php',
					type: 'POST',
					data: 'name=' + name +'&list=' + idlist + '&ajaxattempt=' + ajaxattempt,
					
					success: function(result) {
						
						
						$('.listname').text(name);
						$('.managetitle').hide("slow");
						$('.listname').effect("highlight", {}, 3000);

					}
				});
				
				return false;	
				
}
function delUserFriend(idn)
{
         var id = idn;
		var ajaxattempt = $('#hiddendelFriend').val();
		
        if(confirm("Are you sure?"))
        {			
        	
    				$.ajax({
    				
    					url: 'delete_friend.do',
    					type: 'POST',
    					data: 'id=' + id + '&ajaxattempt=' + ajaxattempt,
    					
    					success: function(result) {
						  
						   	location.reload();
			
						  
					     }
    					
    				});
        }	
        return false;
}
function addUserFriend(idn)
{		  		  
				var id = idn;
				var ajaxattempt = $('#hiddenAddFriend').val();
			
				$.ajax({
								
					url: 'add_friend.do',
					type: 'POST',
					data: 'id=' + id +'&ajaxattempt=' + ajaxattempt,
					
					success: function(result) {
					
						location.reload();
						
					

					}
				});
				
				return false;	
				
}
function addGiftIdea()
{		  		  
				var id = idn.substring(1);
				var ajaxattempt = $('#hiddenAddFriend').val();
				
				$.ajax({
								
					url: 'include/backOfficeHandler.inc.php',
					type: 'POST',
					data: 'id=' + id +'&ajaxattempt=' + ajaxattempt,
					
					success: function(result) {
					
						location.reload();
					

					}
				});
				
				return false;	
				
}

function addGiftIdeaToList(idval)
{				
        var id = idval.substring(1);
		var list = $("#idlist").val();
		var ajaxattempt = $('#hiddenUserGift').val();		
			
					
				$.ajax({
								
					url: 'include/backOfficeHandler.inc.php',
					type: 'POST',
					data: 'idlist=' + list + '&idgift=' + id +'&ajaxattempt=' + ajaxattempt,
				
					success: function(result) {
					
				  $("input#g"+id).hide("slow");
	   						$("input#g"+id).replaceWith('<img src="img/check.png" alt="breve descrizione testuale">');
					    }   
					
				});
				return false;	
}

function changeLang(lan)
{
        var lan = lan;
		//var ajaxattempt = $('#hiddendelFriend').val();
		
       		
        	
    				$.ajax({
    				
    					url: 'language.do',
    					type: 'POST',
    					data: 'lan=' + lan ,
    					
    					success: function(result) {
						  
						   	location.reload();
			
						  
					     }
    					
    				});
        	
        return false;
}

/* progetto j2ee */


